// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require("base");
    var leftMenu = require("../leftMenu/leftMenu");
    var topMenu = require("../topMenu/topMenu");
    var router = require("../hash/pageRouter");
    var footer = require("../footer/footer_main");
    var dialog = require("dialog");
    var validate = require("validate");
    var constant = require("constant");
    var tools = require("tools");
	var databind = require("databind");
    var dailyEarningsDetails= require("./dailyEarningsDetails.html");
    var pressEnterpriseDetailss= require("./pressEnterpriseDetailss.html");
	var storage = window.sessionStorage;
    var fid;
    var deId;
    var inDate;
    var enterpriseDate;
    var firstVisited = 0;
    var auditState;
    var now;
    var enterpriseDate;
    var enterpriseDateNow;
    var dates = new Date
    var leftM;
    var ds;
    var ym;
    var ym2;
    var changeTime;
    var html;
    var interestDt;
    var enterpriseName;
    var financeIds;
    var dates2;
    var enterpriseIds;
    var action;
    var pageIndex = 1,
        pageSize = 10,
        totalPageCount = 1,
        totalRecordCount = 0; //分页初始化
        
    var init = function(){
    	$("#header").html(require("../topMenu/topMenu.html"));
    	firstVisited = base.getUrlParam("firstVisited");
    	leftM = base.getUrlParam("leftM");
    	leftM = leftM == null?4:leftM;
    	footer.init();
    	$("#footer").removeClass("none");
		
    	leftMenu.init(leftM);
    	
    	$(".serviceFeeIncome").parents("li.leftMenu-item").addClass("leftMenu-open");
    	$(".leftMenu-item").removeClass("leftMenu-active");
    	$(".serviceFeeIncome").addClass("leftMenu-active");
    	
    	topMenu.init(2);
    	$(".footer").removeClass("none");
    	
    	showEarningSummaryList();
    	showList("inquireDaysEarningPageList.json");
		initEvent();
		router.init();
		
		if(firstVisited != 1){
			$(".table-section").removeClass("none");
		}
		$(".line1").on("click", "#serviceFffIncomeList", function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化	
			if(action == undefined){
				action=$(this).attr("action");
			}
			showList(action);
		})
		
		$("#main").on("click", "#serviceFeeQuery", function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化	
			if(action == undefined){
				action=$(this).attr("action");
			}
			showList(action);
		})
		
		$("#main").on("click", "#serviceFeeQuery2", function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化	
			if(action == undefined){
				action=$(this).attr("action");
			}
			showList(action);
		})
		
		$("#main").on("click", ".exportYesterdayEarnings", function() {
			exportYesterdayEarnings();
		
		})
		
		$("#main").on("click", ".exportByEnterprise", function() {
			exportByEnterprise();
		
		})
    };
    
	var initEvent = function(){
		//若未登录，则返回登陆页面
		if(base.getData("sid")==null||base.getData("sid")==""||base.getData("sid")==undefined){
			top.location.href="../login/login.html";
		}
		
		$("#applyType span").click(function() {
//			$("#publishFromTime").val("");
			$("#main input[name=enterpriseName]").val("");
			pageIndex = 1;
			$("#applyType span").removeClass("active_applyType");
			$(this).addClass("active_applyType");
			$(this).parent().removeClass("applyType1").removeClass("applyType2").removeClass("applyType3");
			$(this).parent().addClass($(this).attr("applytype"));
			action=$(this).attr("action");
			if(action=="inquireDaysEarningPageList.json"){
				$("#tableS2").css("display","none");
				$("#tableS1").css("display","block");
			}else{
				$("#tableS1").css("display","none");
				$("#tableS2").css("display","block");
			}
			showList(action);
		});
		
		$(".memberGradeAduitList").unbind("click").click(function(){
			router.route("client/memberGradeaudit.html");
		});
		
    };
    
    //每日收益详情时间向前走动
    var inquireDaysEarningDetail2 = function(daysEarningId,interestDate,financeId) {
    	base.fnAjax({
			action: "inquireDaysEarningDetail.json",
			async: false,
			oData: {
				daysEarningId : daysEarningId,
				interestDates : interestDate,
				financeId : financeId
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
					base.alert(2, "无本日账单");
					$("#backward2").addClass("a");
					$("#backward").show("span");
					$("#backwardId").addClass("backward2Span");
					$(".dailyEarningsDetails .center").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1-1*1)+"日");
					$(".dailyEarningsDetails .forwMonth").html("xxxx年xx月xx日");
			    	$(".dailyEarningsDetails .backMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1-1-1*1)+"日").css("visibility","visible");
			    	$("#forward2").removeClass("a");
					$("#forward").hide("span");
					$("#forwardId").removeClass("forward2Span");
				}else{
					$("#backward2").addClass("a");
					$("#backward").show("span");
					$("#backwardId").addClass("backward2Span");
					$(".dailyEarningsDetails .backMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1-1*1)+"日").css("visibility","visible");
				}
				if (data.status == 200) {
					var d = {};
					if(data.datas.length == 0) {
						d.daysEarningNumber = null;
						d.financeNumber = null;
						d.enterpriseName = null;
						d.productType = null;
						d.loanDate = null;
						d.financeAmount = null;
						d.interestRate = null;
						d.bulkstockValuation = null;
						d.financeOffDate = null;
						d.financeDays=null;
						d.financeAmountDays=null;
						d.payMethod=null;
					}else {
						d.daysEarningNumber = data.datas[0].daysEarningNumber;
						d.financeNumber = data.datas[0].financeNumber;
						d.enterpriseName = data.datas[0].enterpriseName;
						d.productType = data.datas[0].productType;
						if(data.datas[0].productType == 1){
							d.productType = "舱单代采";
						}
						if(data.datas[0].productType == 2){
							d.productType = "舱单质押";
						}
						if(data.datas[0].productType == 3){
							d.productType = "仓储质押";
						}
						if(data.datas[0].productType == 4){
							d.productType = "保理融资";
						}
						if(data.datas[0].productType == 5){
							d.productType = "代理采购";
						}
						if(data.datas[0].productType == 6){
							d.productType = "代理销售";
						}
						d.loanDate = data.datas[0].loanDate;
						d.financeAmount = tools.formatCurrency(data.datas[0].financeAmount);
						d.interestRate = data.datas[0].interestRate+"%";
						d.bulkstockValuation = tools.formatCurrency(data.datas[0].bulkstockValuation);
						var newDate=/\d{4}-\d{1,2}-\d{1,2}/g.exec(data.datas[0].financeOffDate);
						d.financeOffDate =newDate;
						d.financeDays = data.datas[0].financeDays+"天";
						d.financeAmountDays = data.datas[0].financeAmountDays+"天";
						d.payMethod ="按月付息到期还本";
						databind.fillForm($(".financeApplicationInfo"), d);
					}
				}
			}
    	});
    };
    
    //每日收益详情时间向后走动
    var inquireDaysEarningDetail = function(daysEarningId,interestDate,financeId) {
    	base.fnAjax({
			action: "inquireDaysEarningDetail.json",
			async: false,
			oData: {
				daysEarningId : daysEarningId,
				interestDates : interestDate,
				financeId : financeId
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
					base.alert(2, "无本日账单");
					$("#backward2").removeClass("a");
					$("#backward").hide("span");
					$("#backwardId").removeClass("backward2Span");
					$("#forwardId").addClass("forward2Span");
					$("#forward2").addClass("a");
					$("#forward").show("span");
					$(".dailyEarningsDetails .center").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1+1*1)+"日");
					$(".dailyEarningsDetails .forwMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1+1+1*1)+"日").css("visibility","visible");
			    	$(".dailyEarningsDetails .backMonth").html("xxxx年xx月xx日");
				}else{
					$("#forwardId").addClass("forward2Span");
					$("#forward2").addClass("a");
					$("#forward").show("span");
					$(".dailyEarningsDetails .forwMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1+1*1)+"日").css("visibility","visible");
				}
				if (data.status == 200) {
					var d = {};
					if(data.datas.length == 0) {
						d.daysEarningNumber = null;
						d.financeNumber = null;
						d.enterpriseName = null;
						d.productType = null;
						d.loanDate = null;
						d.financeAmount = null;
						d.interestRate = null;
						d.bulkstockValuation = null;
						d.financeOffDate = null;
						d.financeDays=null;
						d.financeAmountDays=null;
						d.payMethod=null;
					}else {
						d.daysEarningNumber = data.datas[0].daysEarningNumber;
						d.financeNumber = data.datas[0].financeNumber;
						d.enterpriseName = data.datas[0].enterpriseName;
						d.productType = data.datas[0].productType;
						if(data.datas[0].productType == 1){
							d.productType = "舱单代采";
						}
						if(data.datas[0].productType == 2){
							d.productType = "舱单质押";
						}
						if(data.datas[0].productType == 3){
							d.productType = "仓储质押";
						}
						if(data.datas[0].productType == 4){
							d.productType = "保理融资";
						}
						if(data.datas[0].productType == 5){
							d.productType = "代理采购";
						}
						if(data.datas[0].productType == 6){
							d.productType = "代理销售";
						}
						d.loanDate = data.datas[0].loanDate;
						d.financeAmount = tools.formatCurrency(data.datas[0].financeAmount);
						d.interestRate = data.datas[0].interestRate+"%";
						d.bulkstockValuation = tools.formatCurrency(data.datas[0].bulkstockValuation);
						var newDate=/\d{4}-\d{1,2}-\d{1,2}/g.exec(data.datas[0].financeOffDate);
						d.financeOffDate =newDate;
						d.financeDays = data.datas[0].financeDays+"天";
						d.financeAmountDays = data.datas[0].financeAmountDays+"天";
						d.payMethod ="按月付息到期还本";
						databind.fillForm($(".financeApplicationInfo"), d);
					}
				}
			}
    	});
    };
    
    var inquireDaysEarningDetails_2 = function(daysEarningId,interestDate,financeId) {
    	base.fnAjax({
			action: "inquireDaysEarningDetail.json",
			async: false,
			oData: {
				daysEarningId : daysEarningId,
				interestDates : interestDate,
				financeId : financeId
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
					$("#forward2").removeClass("a");
					$("#forward").hide("span");
					$("#forwardId").removeClass("forward2Span");
					$(".dailyEarningsDetails .forwMonth").html("xxxx年xx月xx日").css("visibility","hidden");
				}else{

				}
			}
    	});
    };
    
    var inquireDaysEarningDetails_3 = function(daysEarningId,interestDate,financeId) {
    	base.fnAjax({
			action: "inquireDaysEarningDetail.json",
			async: false,
			oData: {
				daysEarningId : daysEarningId,
				interestDates : interestDate,
				financeId : financeId
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
					$("#backward2").removeClass("a");
					$("#backward").hide("span");
					$("#backwardId").removeClass("backward2Span");
			    	$(".dailyEarningsDetails .backMonth").html("xxxx年xx月xx日").css("visibility","hidden");
				}else{	
				/*	$("#backward2").addClass("a");
					$("#backward").show("span");
					$("#backwardId").addClass("backward2Span");*/
				}
			}
    	});
    };
    
    //按企业详情时间向后走动
    var inquireSaysEarningEnterpriseDetail = function(interestDt, enterpriseName,financeIds) {
    	base.fnAjax({
			action: "inquireSaysEarningEnterprisePageList.json",
			async: false,
			oData: {
				interestDts : interestDt,
				enterpriseName:enterpriseName,
				financeId : financeIds
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
					base.alert(2, "无本日账单");
					$("#forward3").addClass("a");
					$("#forwardS3").show("span");
					$("#forward3Id").addClass("forward3Span");
					$(".pressEnterpriseDetailss .backMonth3").html("xxxx年xx月xx日");
					$(".pressEnterpriseDetailss .center").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1+1*1)+"日");
					$(".pressEnterpriseDetailss .forwMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1+1+1*1)+"日").css("visibility","visible");
					$("#backward3").removeClass("a");
					$("#backwardS3").hide("span");
					$("#backward3Id").removeClass("backward3Span");
					//TODO 传入当前变更后的日期
				}else{
					$("#forward3").addClass("a");
					$("#forwardS3").show("span");
					$("#forward3Id").addClass("forward3Span");
					$(".pressEnterpriseDetailss .forwMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1+1*1)+"日").css("visibility","visible");
				}				
				if (data.status == 200) {
					var d = {};
					if(data.datas.length == 0) {
						d.enterpriseName = null;
						d.financeAmount = null;
						d.bulkstockValuation = null;
					}else {
						d.enterpriseName = data.datas[0].enterpriseName;
						d.financeAmount =  tools.formatCurrency(data.datas[0].financeAmount);
						d.bulkstockValuation = tools.formatCurrency(data.datas[0].bulkstockValuation);
						databind.fillForm($(".financeApplicationInfo2"), d);
					}
				}
			}
    	});
    };
    
    //按企业前一天
    var inquireSaysEarningEnterpriseDetails_2 = function(interestDt, enterpriseName,financeIds) {
    	base.fnAjax({
			action: "inquireSaysEarningEnterprisePageList.json",
			async: false,
			oData: {
				interestDts : interestDt,
				enterpriseName:enterpriseName,
				financeId : financeIds
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
					$("#forward3").removeClass("a");
					$("#forwardS3").hide("span");
					$("#forward3Id").removeClass("forward3Span");
					$(".pressEnterpriseDetailss .forwMonth3").html("xxxx年xx月xx日").css("visibility","hidden");
					//TODO 传入当前变更后的日期
				}else{
					/*$("#forward3").addClass("a");
					$("#forwardS3").show("span");
					$("#forward3Id").addClass("forward3Span");*/
				}				
			}
    	});
    };
    
    //按企业后一天
    var inquireSaysEarningEnterpriseDetails_3 = function(interestDt, enterpriseName,financeIds) {
    	base.fnAjax({
			action: "inquireSaysEarningEnterprisePageList.json",
			async: false,
			oData: {
				interestDts : interestDt,
				enterpriseName:enterpriseName,
				financeId : financeIds
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
					$("#backward3").removeClass("a");
					$("#backwardS3").hide("span");
					$("#backward3Id").removeClass("backward3Span");
					$(".pressEnterpriseDetailss .backMonth3").html("xxxx年xx月xx日").css("visibility","hidden");
					//TODO 传入当前变更后的日期
				}else{
					/*$("#backward3").addClass("a");
					$("#backwardS3").show("span");
					$("#backward3Id").addClass("backward3Span");*/
				}				
			}
    	});
    };
    
    //按企业详情向前走动
    var inquireSaysEarningEnterpriseDetail2 = function(interestDt, enterpriseName,financeIds) {
    	base.fnAjax({
			action: "inquireSaysEarningEnterprisePageList.json",
			async: false,
			oData: {
				interestDts : interestDt,
				enterpriseName:enterpriseName,
				financeId : financeIds
			}, //传递参数
			fnSuccess: function(data) {
				if(data.datas.length == 0){
				base.alert(2, "无本日账单");
					$("#backward3").addClass("a");
					$("#backwardS3").show("span");
					$("#backward3Id").addClass("backward3Span");
					$(".pressEnterpriseDetailss .center").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1-1*1)+"日");
					$(".pressEnterpriseDetailss .forwMonth3").html("xxxx年xx月xx日");
			    	$(".pressEnterpriseDetailss .backMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1-1-1*1)+"日").css("visibility","visible");
			    	$("#forward3").removeClass("a");
					$("#forwardS3").hide("span");
					$("#forward3Id").removeClass("forward3Span");
				}else{
					$("#backward3").addClass("a");
					$("#backwardS3").show("span");
					$("#backward3Id").addClass("backward3Span");
			    	$(".pressEnterpriseDetailss .backMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1-1*1)+"日").css("visibility","visible");
				}
				if (data.status == 200) {
					var d = {};
					if(data.datas.length == 0) {
						d.enterpriseName = null;
						d.financeAmount = null;
						d.bulkstockValuation = null;
					}else {
						d.enterpriseName = data.datas[0].enterpriseName;
						d.financeAmount =  tools.formatCurrency(data.datas[0].financeAmount);
						d.bulkstockValuation = tools.formatCurrency(data.datas[0].bulkstockValuation);
						databind.fillForm($(".financeApplicationInfo2"), d);
					}
					
				}
			}
    	});
    };
    var showDaysEarningList = function(now, financeId,pageIndex) {
    	base.fnAjax({
			action: "inquireDaysEarningPageList.json",
			async: false,
			oData: {
				interestDates: now,
				financeId: financeId,
				financeNumber: null,
				pageSize: pageSize,
				pageIndex: pageIndex
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("formatCurrency", tools.formatCurrency);
					var applyType = $(".active_applyType").attr("applyType");
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $(".dailyEarningsDetails #dailyEarningsTpls2").html();
					html = juicer(tpl, data);
					if(html != "         "){
						$(".dailyEarningsDetails #daysEarningTable").html(html);
					}
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($(".dailyEarningsDetails #pagerCon_1s"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							showDaysEarningList(now, financeId,pageIndex);
						});
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
    };
    
    var showDaysEarningList2 = function(dates_2,enterpriseIds,pageIndex) {
    	base.fnAjax({
			action: "inquireDaysEarningPageList.json",
			async: false,
			oData: {
				interestDates: null,
				financeNumber: null,
				enterpriseName:null,
				interestDates:dates_2,
				enterpriseId:enterpriseIds,
				pageSize: pageSize,
				pageIndex: pageIndex
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("formatCurrency", tools.formatCurrency);
					var applyType = $(".active_applyType").attr("applyType");
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $(".pressEnterpriseDetailss #byEnterpriseTpls2").html();
					html = juicer(tpl, data);
					if(html != "       "){
						$(".pressEnterpriseDetailss #daysEarningTable_2").html(html);
					}
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($(".pressEnterpriseDetailss #clientPagenation_2"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							showDaysEarningList2(dates_2,enterpriseIds,pageIndex);
						});
					
				/*	$(".order_num2").unbind("click").click(function() {
						var enterpriseId=$(this).parents("tr").attr("enterpriseId");
						storage.setItem("enterpriseId", enterpriseId);
						window.open("../client/clientManageDetailIntact.html");
//						router.route("financing/financingDetailInfo.html?financeId=" + $(this).parents("tr").attr("financeId"));
					});	*/
					
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
    };
    
	//申请列表
	var showList = function(action) {
		if($("#searchEnterprise input[name=createDateTimeBegin]").val() != "" && $("#searchEnterprise input[name=createDateTimeEnd]").val() != ""){
			var dates2= $("#searchEnterprise input[name=createDateTimeBegin]").val();
			var createDateTimeEnd= $("#searchEnterprise input[name=createDateTimeEnd]").val();
		}else if($("#searchEnterprise input[name=createDateTimeBegin]").val() != ""){
			var dates2= $("#searchEnterprise input[name=createDateTimeBegin]").val();
		}else if($("#searchEnterprise input[name=createDateTimeEnd]").val() != ""){
			var dates2= $("#searchEnterprise input[name=createDateTimeEnd]").val();
		}else{
			dates2=dates.getFullYear()+"-"+(dates.getMonth()*1+1*1)+"-"+(dates.getDate()*1-1*1);
		}
		var financeNumber=$("#main input[name=financeNumber]").val();
		var enterpriseName;
		if($("#tableS2 input[name=enterpriseName]").val()!=""){
			enterpriseName=$("#tableS2 input[name=enterpriseName]").val();
		}else{
			enterpriseName=$("#tableS1 input[name=enterpriseName]").val();
		}
		base.fnAjax({
			action: action,
			async: false,
			oData: {
				interestDates:dates2,
				interestDts:dates2,
				createDateTimeEnd:createDateTimeEnd,
				financeNumber:financeNumber,
				enterpriseName:enterpriseName,
				pageSize: pageSize,
				pageIndex: pageIndex
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("formatCurrency", tools.formatCurrency);
					juicer.register("getValueByKey", constant.getValueByKey);
					
					if(action == "inquireSaysEarningEnterprisePageList.json"){
						var tpl = $("#accountRecordApplyListTpl1").html();
						var html = juicer(tpl, data);
						$("#accountRecordApplyListBodyss").html(html);
					} else{
						var tpl = $("#accountRecordApplyListTpl").html();
						var html = juicer(tpl, data);
						$("#accountRecordApplyListBodyss").html(html);
//						$(".dates").html(dates.getFullYear()+"-"+(dates.getMonth()*1+1*1)+"-"+(dates.getDate()*1-1*1));
					}
					
					//每日收益详情
					$(".detailApplication").unbind("click").click(function(){
						fid = $(this).parents("tr").attr("financeId");
						deId=$(this).parents("tr").attr("daysEarningId")
						inDate=$(this).parents("tr").attr("interestDate");
						var array =inDate.split("-");
						now = new Date(array[0], array[1]-1, array[2]);
						var ii = layer.open({
						  title: ' ',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['750px', '600px'], //宽高900px
						  content: dailyEarningsDetails,
						});
						
						$(".dailyEarningsDetails .center").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+now.getDate()+"日");
				    	$(".dailyEarningsDetails .forwMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1+1*1)+"日");
				    	$(".dailyEarningsDetails .backMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1-1*1)+"日");
						
						var $chargeDayContentPar = $(".dailyEarningsDetails").parent();
						$chargeDayContentPar.siblings("div.layui-layer-btn").remove();
						$chargeDayContentPar.siblings("div.layui-layer-title").css("background-color", "#0099FA");
						// 向前
						$(".dailyEarningsDetails").on("click", ".forward2Span", function() {
							now = new Date(tools.addDate(now, 1));
							$(".dailyEarningsDetails .center").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+now.getDate()+"日");
							$(".dailyEarningsDetails .forwMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1+1*1)+"日");
					    	$(".dailyEarningsDetails .backMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1-1*1)+"日");
					    	//TODO 传入当前变更后的日期
					    	inquireDaysEarningDetail2(null,now.getFullYear()+ "-" +(now.getMonth()*1+1*1)+ "-" +now.getDate(), fid);
					    	inquireDaysEarningDetails_2(null,now.getFullYear()+"-"+(now.getMonth()*1+1*1)+"-"+(now.getDate()*1+1*1), fid);
					    	var inDate = now.getFullYear()+ "-" +(now.getMonth()*1+1*1)+ "-" +now.getDate();
							showDaysEarningList(inDate, fid,pageIndex = 1);
						})
						
						// 向后
						$(".dailyEarningsDetails").on("click", ".backward2Span", function() {
							now = new Date(tools.addDate(now, -1));
							$(".dailyEarningsDetails .center").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+now.getDate()+"日");
							$(".dailyEarningsDetails .forwMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1+1*1)+"日");
					    	$(".dailyEarningsDetails .backMonth").html(now.getFullYear()+"年"+(now.getMonth()*1+1*1)+"月"+(now.getDate()*1-1*1)+"日");
					    	//TODO 传入当前变更后的日期
					    	inquireDaysEarningDetail(null,now.getFullYear()+ "-" +(now.getMonth()*1+1*1)+ "-" +now.getDate(), fid);
							inquireDaysEarningDetails_3(null,now.getFullYear()+"-"+(now.getMonth()*1+1*1)+"-"+(now.getDate()*1-1*1), fid);

					    	var inDate = now.getFullYear()+ "-" +(now.getMonth()*1+1*1)+ "-" +now.getDate();
					    	showDaysEarningList(inDate, fid,pageIndex = 1);
						})
						//查询单日信息
						inquireDaysEarningDetail($(this).parents("tr").attr("daysEarningId"),$(this).parents("tr").attr("interestDate"), $(this).parents("tr").attr("financeId"));
						//查询前一天信息
						inquireDaysEarningDetails_2(null,now.getFullYear()+"-"+(now.getMonth()*1+1*1)+"-"+(now.getDate()*1+1*1), fid);
						//查询后一天信息
						inquireDaysEarningDetails_3(null,now.getFullYear()+"-"+(now.getMonth()*1+1*1)+"-"+(now.getDate()*1-1*1), fid);
						
						showDaysEarningList($(this).parents("tr").attr("interestDate"), $(this).parents("tr").attr("financeId"),pageIndex = 1);
					});
					
					//按企业详情
					$(".detailApplication2").unbind("click").click(function(){
						enterpriseDate=$(this).parents("tr").attr("interestDt");
						enterpriseName=$(this).parents("tr").attr("enterpriseName");
						financeIds=$(this).parents("tr").attr("financeId");
						enterpriseIds=$(this).parents("tr").attr("enterpriseId");
						var array =enterpriseDate.split("-");
						enterpriseDateNow = new Date(array[0], array[1]-1, array[2]);
						var ii = layer.open({
						  title: ' ',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['985px', '587px'], //587px宽高
						  content: pressEnterpriseDetailss
						  
						});
						
						$(".pressEnterpriseDetailss .center").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+enterpriseDateNow.getDate()+"日");
				    	$(".pressEnterpriseDetailss .forwMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1+1*1)+"日");
				    	$(".pressEnterpriseDetailss .backMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1-1*1)+"日");
						
						var $chargeDayContentPar = $(".pressEnterpriseDetailss").parent();
						$chargeDayContentPar.siblings("div.layui-layer-btn").remove();
						$chargeDayContentPar.siblings("div.layui-layer-title").css("background-color", "#0099FA");
						$chargeDayContentPar.siblings("div.layui-layer-title").siblings().css("overflow","visible");
						// 向前
						$(".pressEnterpriseDetailss").on("click", ".forward3Span", function() {
							enterpriseDateNow = new Date(tools.addDate(enterpriseDateNow, 1));
							$(".pressEnterpriseDetailss .center").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+enterpriseDateNow.getDate()+"日");
							$(".pressEnterpriseDetailss .forwMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1+1*1)+"日");
					    	$(".pressEnterpriseDetailss .backMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1-1*1)+"日");
					    	//TODO 传入当前变更后的日期
					    	inquireSaysEarningEnterpriseDetail2(enterpriseDateNow.getFullYear()+ "-" +(enterpriseDateNow.getMonth()*1+1*1)+ "-" +enterpriseDateNow.getDate(), enterpriseName,financeIds); 
					    	inquireSaysEarningEnterpriseDetails_2(enterpriseDateNow.getFullYear()+"-"+(enterpriseDateNow.getMonth()*1+1*1)+"-"+(enterpriseDateNow.getDate()*1+1*1),enterpriseName,financeIds); 
					    	var inDate = enterpriseDateNow.getFullYear()+ "-" +(enterpriseDateNow.getMonth()*1+1*1)+ "-" +enterpriseDateNow.getDate();
							showDaysEarningList2(inDate, enterpriseIds,pageIndex = 1);
						})
						
						// 向后
						$(".pressEnterpriseDetailss").on("click", ".backward3Span", function() {//backward
							enterpriseDateNow = new Date(tools.addDate(enterpriseDateNow, -1));
							$(".pressEnterpriseDetailss .center").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+enterpriseDateNow.getDate()+"日");
							$(".pressEnterpriseDetailss .forwMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1+1*1)+"日");
					    	$(".pressEnterpriseDetailss .backMonth3").html(enterpriseDateNow.getFullYear()+"年"+(enterpriseDateNow.getMonth()*1+1*1)+"月"+(enterpriseDateNow.getDate()*1-1*1)+"日");
					    	//TODO 传入当前变更后的日期
					    	inquireSaysEarningEnterpriseDetail(enterpriseDateNow.getFullYear()+ "-" +(enterpriseDateNow.getMonth()*1+1*1)+ "-" +enterpriseDateNow.getDate(), enterpriseName,financeIds);
					    	inquireSaysEarningEnterpriseDetails_3(enterpriseDateNow.getFullYear()+"-"+(enterpriseDateNow.getMonth()*1+1*1)+"-"+(enterpriseDateNow.getDate()*1-1*1),enterpriseName,financeIds); 
					    	var inDate = enterpriseDateNow.getFullYear()+ "-" +(enterpriseDateNow.getMonth()*1+1*1)+ "-" +enterpriseDateNow.getDate();
					    	showDaysEarningList2(inDate, enterpriseIds,pageIndex = 1);
						})
						//查询单日账单
						inquireSaysEarningEnterpriseDetail($(this).parents("tr").attr("interestDt"),enterpriseName,financeIds); 
						//查询前一天账单日期
						inquireSaysEarningEnterpriseDetails_2(enterpriseDateNow.getFullYear()+"-"+(enterpriseDateNow.getMonth()*1+1*1)+"-"+(enterpriseDateNow.getDate()*1+1*1),enterpriseName,financeIds); 
						//查询后一天账单日期
						inquireSaysEarningEnterpriseDetails_3(enterpriseDateNow.getFullYear()+"-"+(enterpriseDateNow.getMonth()*1+1*1)+"-"+(enterpriseDateNow.getDate()*1-1*1),enterpriseName,financeIds); 
						showDaysEarningList2(enterpriseDate,enterpriseIds,pageIndex = 1);
					});
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($("#changepage"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;	
							showList(action);
						});
					
					//点击融资编号
					/*$(".order_num").unbind("click").click(function() {
						var enterpriseId=$(this).parents("tr").attr("enterpriseId");
						storage.setItem("enterpriseId", enterpriseId);
						window.open("../client/clientManageDetailIntact.html");
					});	
					
					//企业名称
					$(".enter_name").unbind("click").click(function() {
						var enterpriseId=$(this).parents("tr").attr("enterpriseId");
						storage.setItem("enterpriseId", enterpriseId);
						window.open("../client/clientManageDetailIntact.html");
					});
					
					//企业名称
					$(".enterprise_Date").unbind("click").click(function() {
						var enterpriseId=$(this).parents("tr").attr("enterpriseId");
						storage.setItem("enterpriseId", enterpriseId);
						window.open("../client/clientManageDetailIntact.html");
					});*/
					
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//申请列表
	var showEarningSummaryList = function() {
		base.fnAjax({
			action:"inquireEarningSummarys.json",
			async: false,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var loanAmount = data.datas[0].loanAmount;
					var loanAmountIncrease = data.datas[0].loanAmountIncrease;
					var loanAmountRiseFall = data.datas[0].loanAmountRiseFall;
					
					var yestodayEarning = data.datas[0].yestodayEarning;
					var yestodayEarningIncrease = data.datas[0].yestodayEarningIncrease;
					var yestodayEarningRiseFall = data.datas[0].yestodayEarningRiseFall;
					
					var totalEarning = data.datas[0].totalEarning;
					var totalEarningIncrease = data.datas[0].totalEarningIncrease;
					var totalEarningRiseFall = data.datas[0].totalEarningRiseFall;
					$("#loanAmount").html(tools.formatCurrency((loanAmount / 10000).toFixed(2)));
					if(loanAmountIncrease>0){
						$("#rihuanbi1").attr("src","../../../res/png/u11415.png");
					}else{
						$("#rihuanbi1").attr("src","../../../res/png/u11408.png").css('transform','rotate(180deg)');
					}
					$("#loanAmountIncrease").html(tools.formatCurrency(loanAmountIncrease) + "%");
					$("#loanAmountRiseFall").html(tools.formatCurrency((loanAmountRiseFall / 10000).toFixed(2)));
					$("#yestodayEarning").html("+"+tools.formatCurrency((yestodayEarning / 10000).toFixed(2)));
					if(yestodayEarningIncrease>0){
						$("#rihuanbi2").attr("src","../../../res/png/u11415.png");
					}else{
						$("#rihuanbi2").attr("src","../../../res/png/u11408.png").css('transform','rotate(180deg)');
					}
					$("#yestodayEarningIncrease").html(tools.formatCurrency(yestodayEarningIncrease) + "%");
					$("#yestodayEarningRiseFall").html(tools.formatCurrency((yestodayEarningRiseFall / 10000).toFixed(2)));
					$("#totalEarning").html("+"+tools.formatCurrency((totalEarning / 10000).toFixed(2)));
					if(totalEarningIncrease>0){
						$("#rihuanbi3").attr("src","../../../res/png/u11415.png");
					}else{
						$("#rihuanbi3").attr("src","../../../res/png/u11408.png").css('transform','rotate(180deg)');
					}
					$("#totalEarningIncrease").html(tools.formatCurrency(totalEarningIncrease) + "%");	
					$("#totalEarningRiseFall").html(tools.formatCurrency((totalEarningRiseFall / 10000).toFixed(2)));
				} else {
					    base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	// 导出
    var exportYesterdayEarnings = function() {
    		var createDateTimeEnd="";
	    	if($("#searchEnterprise input[name=createDateTimeBegin]").val() != "" && $("#searchEnterprise input[name=createDateTimeEnd]").val() != ""){
				var dates2= $("#searchEnterprise input[name=createDateTimeBegin]").val();
				createDateTimeEnd= $("#searchEnterprise input[name=createDateTimeEnd]").val();
			}else if($("#searchEnterprise input[name=createDateTimeBegin]").val() != ""){
				var dates2= $("#searchEnterprise input[name=createDateTimeBegin]").val();
			}else if($("#searchEnterprise input[name=createDateTimeEnd]").val() != ""){
				var dates2= $("#searchEnterprise input[name=createDateTimeEnd]").val();
			}else{
				dates2=dates.getFullYear()+"-"+(dates.getMonth()*1+1*1)+"-"+(dates.getDate()*1-1*1);
			}
			var financeNumber=$("#main input[name=financeNumber]").val();
			var	enterpriseName=$("#tableS1 input[name=enterpriseName]").val();
	    	location.href="/finance/api/v1.0/exportYesterdaysEarnings.json?interestDates=" + dates2 + "&createDateTimeEnd=" + createDateTimeEnd + "&financeNumber=" + financeNumber +"&enterpriseName=" +enterpriseName;
//    		base.fnAjax({
//			action: "/finance/api/v1.0/exportYesterdaysEarnings.json",
//			async: true,
//			nocode: true,
//			oData: {
//				interestDates:dates2,
//				createDateTimeEnd:createDateTimeEnd
//			}, //传递参数
//			fnSuccess: function(data) {
//				if (data.status == 200) {
//					base.alert(1, "导出成功");
//				}else {
//					base.alert(2, data.message);
//				}
//			}
//		})
    };
    
 // 导出
    var exportByEnterprise = function() {
    		var createDateTimeEnd="";
	    	if($("#searchEnterprise input[name=createDateTimeBegin]").val() != "" && $("#searchEnterprise input[name=createDateTimeEnd]").val() != ""){
				var dates2= $("#searchEnterprise input[name=createDateTimeBegin]").val();
				createDateTimeEnd= $("#searchEnterprise input[name=createDateTimeEnd]").val();
			}else if($("#searchEnterprise input[name=createDateTimeBegin]").val() != ""){
				var dates2= $("#searchEnterprise input[name=createDateTimeBegin]").val();
			}else if($("#searchEnterprise input[name=createDateTimeEnd]").val() != ""){
				var dates2= $("#searchEnterprise input[name=createDateTimeEnd]").val();
			}else{
				dates2=dates.getFullYear()+"-"+(dates.getMonth()*1+1*1)+"-"+(dates.getDate()*1-1*1);
			}
	    	var enterpriseName=$("#tableS2 input[name=enterpriseName]").val();
	    	location.href="/finance/api/v1.0/exportByEnterprise.json?interestDts=" + dates2 + "&createDateTimeEnd=" + createDateTimeEnd + "&enterpriseName=" + enterpriseName;
			
//    		base.fnAjax({
//			action: "exportByEnterprise.json",
//			async: true,
//			nocode: true,
//			oData: {
//				interestDts:dates2,
//				createDateTimeEnd:createDateTimeEnd
//			}, //传递参数
//			fnSuccess: function(data) {
//				if (data.status == 200) {
//					base.alert(1, "导出成功");
//				}else {
//					base.alert(2, data.message);
//				}
//			}
//		})
    };
    return {
        init:init
    };
});